﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Xml.Serialization;
using Yottamud_Project_V3;

namespace Yottamud_2013_v3_Main
{
    public class SystemSettings
    {
        public class SystemSettingType
        {
            public string DatabaseFileName { get; set; }
            public string BBSName { get; set; }
            public int BBSPort { get; set; }
            public string BBSAddress { get; set; }
            public int DisplayHeight { get; set; }
            public int DisplayWidth { get; set; }
            public string DisplayFontName { get; set; }
            public float DisplayFontSize { get; set; }
            public FontStyle DisplayFontStyle { get; set; }
            public string BBSUserName { get; set; }
            public string BBSPassword { get; set; }
            public GameDataMonitor.GameTrigger UsernameTrigger { get; set; }
            public GameDataMonitor.GameTrigger PasswordTrigger { get; set; }
            public int ClassName { get; set; }
            public int RaceName { get; set; }

            public PlayerManager.PlayerAutoHealthSettings PlayerAutoSettings
            {
                get;
                set;
            }

            [XmlIgnore]
            public Font PaintFont { get; set; }
        }

        private SystemSettingsWindow _inputGUI;
        public SystemSettingType SystemSetting = new SystemSettingType();

        public SystemSettings(SystemSettingsWindow inputGUI)
        {
            _inputGUI = inputGUI;
        }

        /// <summary>
        /// NewSystemSettings, resets the system settings to default state.
        /// </summary>
        public void NewSystemSettings()
        {
            SystemSetting = new SystemSettingType();


            SystemSetting.BBSPort = 0;
            SystemSetting.BBSName = "";
            SystemSetting.BBSAddress = "";
            SystemSetting.DatabaseFileName = "";
            SystemSetting.DisplayFontName = "Consolas";
            SystemSetting.DisplayFontSize = 12;
            SystemSetting.DisplayFontStyle = FontStyle.Regular;
            SystemSetting.DisplayHeight = 30;
            SystemSetting.DisplayWidth = 80;
            SystemSetting.PlayerAutoSettings = new PlayerManager.PlayerAutoHealthSettings();
            SystemSetting.PaintFont = new System.Drawing.Font(SystemSetting.DisplayFontName,
                                                                    SystemSetting.DisplayFontSize,
                                                                    SystemSetting.DisplayFontStyle);

        }
        /// <summary>
        /// LoadSystemSettings, allows the user to load a previously saved system setting file.
        /// </summary>
        /// <param name="iFileName"></param>
        public void LoadSystemSettings(string iFileName)
        {
            if (File.Exists(iFileName))
            {
                XMLUtility.ReadFromXML(out SystemSetting, iFileName);

               
                SystemSetting.PaintFont = new System.Drawing.Font(SystemSetting.DisplayFontName,
                                                                    SystemSetting.DisplayFontSize,
                                                                    SystemSetting.DisplayFontStyle);
            }
        }

        //public void UpdateSystemSetting()
        //{


        //    SystemSetting.BBSAddress = _inputGUI.txtBBSAddress.Text;
        //    SystemSetting.BBSName = _inputGUI.txtBBSName.Text;
        //    SystemSetting.BBSPort = int.Parse(_inputGUI.txtBBSPort.Text);
        //    SystemSetting.DatabaseFileName = _inputGUI.txtDatabaseFile.Text;
        //    SystemSetting.DisplayFontName = SystemSetting.PaintFont.Name;
        //    SystemSetting.DisplayFontSize = SystemSetting.PaintFont.Size;
        //    SystemSetting.DisplayFontStyle = SystemSetting.PaintFont.Style;
        //    SystemSetting.DisplayHeight = (int)_inputGUI.nbDisplayHeight.Value;
        //    SystemSetting.DisplayWidth = (int)_inputGUI.nbDisplayWidth.Value;
            

        //}

        public void SaveSystemSettings(string iSettingFileName)
        {
            if (SystemSetting != null)
            {
                XMLUtility.WriteToXML(SystemSetting, iSettingFileName);
            }
        }    
    }
}
